package com.java46.front.order.service;

import com.java46.front.base.exception.BusinessException;
import com.java46.front.order.dao.OrderDao;
import com.java46.front.order.entity.OrderinfoEntity;
import com.java46.front.order.entity.OrdersEntity;

public class OrderService {
    private OrderDao orderDao=new OrderDao();
    //添加订单
    public void addOrders(int userId,String time)
    {
        OrdersEntity orders = new OrdersEntity();
        orders.setOrderState(0);
        orders.setPayMethod(1);
        orders.setTime(time);
        orders.setUserId(userId);
        orderDao.addOrders(orders);
    }
    //根据用户ID和下单时间得到一个Orders对象
    public OrdersEntity getOrders(String userId,String time){
        if(userId==null&&"".equals(userId)||time==null&&"".equals(time)){
            throw new BusinessException("商品订单的信息为空...");
        }
        return orderDao.getOrders(Integer.parseInt(userId),time);
    }
    //添加订单详情
    public void addOrderInfo(int orderId, String count,String dessertId)
    {
        if(count==null&&"".equals(count)||dessertId==null&&"".equals(dessertId)){
            throw new BusinessException("商品订单的信息为空...");
        }
        OrderinfoEntity orderinfoEntity = new OrderinfoEntity();
        orderinfoEntity.setCount(Integer.parseInt(count));
        orderinfoEntity.setDessertId(Integer.parseInt(dessertId));
        orderinfoEntity.setOrderId(orderId);
        orderDao.addOrderInfo(orderinfoEntity);
    }
}
